package cn.edu.gdut.deepcode.config;

import io.minio.MinioClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * <p>
 * </p>
 *
 * @Author: 暮倦
 * @Since: 2025-04-13  11:33
 * @Version: 1.0.0
 */
@Component
@EnableConfigurationProperties(SnapshotTaskProperties.class)
public class SnapshotTaskConfig {

    @Bean
    public ExecutorService genSnapshotTaskExecutorService(SnapshotTaskProperties properties){
        return new ThreadPoolExecutor(
                properties.getCore(),
                properties.getMaxSize(),
                properties.getLifeTime(),
                properties.getTimeUnit(),
                new LinkedBlockingDeque<>(properties.getExecutorTaskQueueSize()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }

    @Bean
    public LinkedBlockingQueue<Long> managerTaskQueue(SnapshotTaskProperties properties){
        return new LinkedBlockingQueue<>(properties.getManagerTaskQueueSize());
    }

    @Bean
    public MinioClient minioClient(MinIOProperties properties){
        return MinioClient.builder()
                .endpoint(properties.getEndpoint())
                .credentials(properties.getAccessKey(), properties.getSecretKey())
                .build();
    }
}


